package org.example.leetcode.interview.matrix;

public class LC0036 {
    public boolean isValidSudoku(char[][] board) {
        int[][] row = new int[9][10];
        int[][] col = new int[9][10];
        int[][] box = new int[9][10];

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') {
                    continue;
                }
                int curr = board[i][j] - '0';
                if (row[i][curr] == 1) {
                    return false;
                }
                if (col[j][curr] == 1) {
                    return false;
                }

                if (box[j / 3 + (i / 3) * 3][curr] == 1) {
                    return false;
                }
                row[i][curr] = 1;
                col[j][curr] = 1;
                box[j / 3 + (i / 3) * 3][curr] = 1;
            }
        }

        return true;
    }
}
